<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="viewport" content="user-scalable=no">
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta name="format-detection" content="telephone=no" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>委托代购和代售记录</title>
    <link rel="stylesheet" href="../../css/reset.css">
    <style>
        body {
            width: 100%;
            background-color: #fff;
            font-size: 0.28rem;
            /* padding-top: 0.5rem; */
            height: auto;
            -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
            font-family: Helvetica;
            color: #333333;
        }

        .showlist {
            margin-top: 0.16rem;
            background-color: #fff;
        }

        .listtitle {
            width: 100%;
            border-bottom: 1px solid #d9d9d9;
        }

        #showcoinList {
            width: 100%;
            height: auto;
            display: flex;
            display: -webkit-flex;
            justify-content: space-around;
        }

        #showcoinList li {
            padding: 0 0.1rem;
            height: 0.9rem;
            border-bottom: 1px solid #fff;
            line-height: 0.9rem;
        }

        #showcoinList li:first-of-type {
            border-bottom: 1px solid #fad203;
        }

        .listdetail {
            width: 100%;
            height: auto;
            display: flex;
            display: -webkit-flex;
            flex-direction: column;
        }

        .listdetail li {
            width: 100%;
            box-sizing: border-box;
            height: 2.4rem;
            display: flex;
            display: -webkit-flex;
            flex-direction: column;
            padding: 0 0.3rem;
            border-bottom: 1px solid #d9d9d9;
        }

        .backchoose {
            height: 0.82rem;
            display: flex;
            display: -webkit-flex;
            justify-content: space-between;
            align-items: center;
        }

        .priceDetail {
            box-sizing: border-box;
            width: 100%;
            display: flex;
            display: -webkit-flex;
            font-size: 0.24rem;
            justify-content: space-between;
            color: #cac5b8;
        }

        .priceDetail div p:not(first-of-type) {
            margin: 0.13rem 0;
        }
    </style>
</head>

<body>
    <div class="showlist">
        <div style="box-sizing:boeder-box;padding-bottom: 0.3rem;">
            <ul class="listdetail" id="ul_list">
            </ul>
            <div id="listState" style="text-align: center;margin: auto;color: #666666;margin-top: 10px;">

            </div>
        </div>
    </div>
    <script src="../../js/autosize.js"></script>
    <script src="../../script/jquery_three_two_one.js"></script>
    <script src="../../script/fastclick.js"></script>
    <script src="../../script/dotmin.js"></script>
    <script src="../../script/app.js"></script>
    <script>
        apiready = function () {
            var app = new APP();
            var account = app.getAccount();
            var chooseTime = "desc";
            var chooseType = "sell";
            var chooseCoin = "BTC";
            var curPage = 1;
            var totalPage = 0;
            api.addEventListener({
                name: "tradingRecord"
            },
                function (ret) {
                    app.log("委托列表记录", JSON.stringify(ret));
                    if (ret && ret.value) {
                        changeParams(ret.value);
                        $("body").scrollTop(0);
                        $("#ul_list").empty();
                    }
                }
            );

            function changeParams(data) {
                if (data.chooseTime == "true") {
                    chooseTime = "asc";
                } else {
                    chooseTime = "desc";
                }
                if (data.chooseType == "true") {
                    chooseType = "sell";
                } else {
                    chooseType = "buy";
                }
                if (data.chooseRecordData == "BTC") {
                    chooseCoin = "BTC";
                } else if (data.chooseRecordData == "ETH") {
                    chooseCoin = "ETH";
                } else if (data.chooseRecordData == "LTC") {
                    chooseCoin = "LTC";
                } else if (data.chooseRecordData == "BCNY") {
                    chooseCoin = "BCNY";
                } else if (data.chooseRecordData == "BHPC") {
                    chooseCoin = "BHPC";
                } else {
                    chooseCoin = "BHP";
                }
                getListshow(true);
            }
            function getListshow(isdown) {
                app.ajax({
                    param: {
                        method: "post",
                        url: app.config.url + "wallet/entrustTradingList",
                        data: {
                            values: {
                                uid: account.uid,
                                token: account.token,
                                page: curPage,
                                trade_type: chooseType,
                                currency_name: chooseCoin,
                                sort: chooseTime,
                                trade_status: "30,0"
                            }
                        },
                        callback: function (ret, err) {
                            app.log("委托列表记录", "获取列表返回：" + JSON.stringify(ret));
                            app.stopRefresh();
                            if (ret.code == 1) {
                                totalPage = ret.total_page;
                                ret.list.map(function (item) {
                                    if (item.currency_name == "BHP") {
                                        item.num = String(item.num).replace(/([0-9]+\.[0-9]{4})[0-9]*/, "$1");
                                        item.ex_num = String(item.ex_num).replace(/([0-9]+\.[0-9]{4})[0-9]*/, "$1");
                                    }
                                })
                                // 渲染模板
                                var temp = doT.template($("#indentSellScuess").text());
                                if (isdown) {
                                    $("#ul_list").html(temp(ret.list));
                                } else {
                                    $("#ul_list").append(temp(ret.list));
                                }
                                if (curPage == 1 && ret.list.length == 0) {
                                    $("#listState").text("暂时没有相关数据");
                                }
                            } else {
                                app.toast(ret.message);
                            }
                        }
                    },
                    extra: {
                        isflower: true,
                        delay: 200
                    }
                });
            }
            getListshow(true);
            app.downRefresh(function () {
                app.log("委托列表记录",
                    "curPage下来刷新: " +
                    curPage +
                    " currency_name: " +
                    chooseCoin +
                    " trade_type: " +
                    chooseType +
                    " sort: " +
                    chooseTime
                );
                curPage = 1;
                totalPage = 0;
                $("#ul_list").empty();
                getListshow(true);
            });
            app.toBottom(function () {
                app.log("委托列表记录",
                    "curPage滚动到了底部: " +
                    curPage +
                    " currency_name: " +
                    chooseCoin +
                    " trade_type: " +
                    chooseType +
                    " sort: " +
                    chooseTime
                );
                if (curPage < totalPage) {
                    curPage++;
                    getListshow(false);
                }
            });
        };
    </script>
    <script id="indentSellScuess" type="text/html">
    {{~it:value:index}}
    <li>
        <div class="backchoose">
            <p>
                <span style="color:{{=value.trade_type=='buy'? '#ff6678':'#7ed321' }};background-color:{{=value.trade_type=="buy"? "#ffe4e6":"#e0f4d2" }};display: inline-block;height: 0.36rem;width:1.1rem;font-size: 0.24rem;text-align: center;line-height: 0.36rem;border-radius: 0.05rem;">
                    {{=value.trade_type=="buy"? "委托代购":"委托代售" }}
                </span>
                <span style="color:#b7b09d;font-size: 0.24rem">
                    {{=value.currency_name}}
                </span>
            </p>
            <span style="color:#b5b5b5;font-size: 0.25rem;display:inline-block;width:1.2rem;">
                {{?value.trade_status==0}}
                已取消
                {{??value.trade_status==10}}
                新建
                {{??value.trade_status==20}}
                部分成交
                {{??value.trade_status==30}}
                全部成交
                {{?}}
            </span>
        </div>
        <div class="priceDetail">
            <div>
                <p>
                    成交价格(BCNY)：<span style="color:{{=value.trade_type=='buy'? '#ff6678':'#7ed321' }};">
                        {{=value.unit_price}}
                    </span>
                </p>
                <p>
                    成交金额(BCNY)：<span style="color:#dedad3;">
                        {{=value.user_amount}}
                    </span>
                </p>
                <p style="color:#dedad3">
                    委托时间：<span>
                        {{=value.create_time}}
                    </span>
                </p>
            </div>
            <div style="flex:1;padding-left:0.2rem;">
                <p>
                    委托数量：<span style="color:#4f4d46;">
                        {{=value.num}}
                    </span>
                </p>
                <p>
                    成交数量：<span style="color:#4f4d46;">
                        {{=value.ex_num}}
                    </span>
                </p>
            </div>
        </div>
    </li>
    {{~}}
    </script>
</body>

</html>